from flask import Flask, request
from flask_cors import CORS
import datetime
import logging
from logging import FileHandler
from views.company import bp_company
from utils.comm import Config


def create_app():
    app = Flask(__name__)
    with app.app_context():
        pass
    return app


app = create_app()

app.register_blueprint(bp_company)

app.config.from_object(Config)


@app.route('/aaa')
async def say_hello():
    str1 = '请求ip' + request.remote_addr + ',请求的url' + request.url + '错误信息' + '\n'
    app.logger.error(str1)
    return {'message': 'Hello!'}


cors = CORS(app)

if __name__ == "__main__":
    filename = datetime.datetime.strftime(datetime.datetime.now(), '%Y%m')
    handler = logging.FileHandler('logs/' + filename + '.txt', encoding='utf8')
    app.logger.addHandler(handler)
    app.run(debug=True)
